﻿<template>
  <a-modal
    title="编辑门诊诊断"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="VISIT_NO " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入VISIT_NO " v-decorator="['visitNo']" />
        </a-form-item>
        <a-form-item label="SEQ_NO " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入SEQ_NO " v-decorator="['seqNo']" />
        </a-form-item>
        <a-form-item label="DIAGNOSE_FLAG " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入DIAGNOSE_FLAG " v-decorator="['diagnoseFlag']" />
        </a-form-item>
        <a-form-item label="PATIENT_NAME " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入PATIENT_NAME " v-decorator="['patientName']" />
        </a-form-item>
        <a-form-item label="PATIENT_AGE " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入PATIENT_AGE " v-decorator="['patientAge']" />
        </a-form-item>
        <a-form-item label="PATIENT_SEX " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入PATIENT_SEX " v-decorator="['patientSex']" />
        </a-form-item>
        <a-form-item label="DIAGNOSE_CODE " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入DIAGNOSE_CODE " v-decorator="['diagnoseCode']" />
        </a-form-item>
        <a-form-item label="DIAGNOSE_NAME " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入DIAGNOSE_NAME " v-decorator="['diagnoseName']" />
        </a-form-item>
        <a-form-item label="DIAGNOSE_REMARK " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入DIAGNOSE_REMARK " v-decorator="['diagnoseRemark']" />
        </a-form-item>
        <a-form-item label="INPUT_DATE " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择INPUT_DATE " v-decorator="['inputDate']" @change="onChangeinputDate"/>
        </a-form-item>
        <a-form-item label="ENSURE_DATE " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择ENSURE_DATE " v-decorator="['ensureDate']" @change="onChangeensureDate"/>
        </a-form-item>
        <a-form-item label="CHECK_DATE " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-date-picker style="width: 100%" placeholder="请选择CHECK_DATE " v-decorator="['checkDate']" @change="onChangecheckDate"/>
        </a-form-item>
        <a-form-item label="DOC_CODE " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入DOC_CODE " v-decorator="['docCode']" />
        </a-form-item>
        <a-form-item label="CHECK_CODE " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入CHECK_CODE " v-decorator="['checkCode']" />
        </a-form-item>
        <a-form-item label="CURE_RESULT " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入CURE_RESULT " v-decorator="['cureResult']" />
        </a-form-item>
        <a-form-item label="ENSURE_FLAG " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入ENSURE_FLAG " v-decorator="['ensureFlag']" />
        </a-form-item>
        <a-form-item label="OUTP_NO " :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入OUTP_NO " v-decorator="['outpNo']" />
        </a-form-item>
        <a-form-item v-show="false"><a-input v-decorator="['iD']" /></a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import moment from 'moment'
  import {
    OutpDiagnoseEdit
  } from '@/api/modular/main/OutpDiagnoseManage'
  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        inputDateDateString: '',
        ensureDateDateString: '',
        checkDateDateString: '',
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      moment,
      // 初始化方法
      edit (record) {
        this.visible = true
        setTimeout(() => {
          this.form.setFieldsValue(
            {
              iD: record.iD,
              visitNo: record.visitNo,
              seqNo: record.seqNo,
              diagnoseFlag: record.diagnoseFlag,
              patientName: record.patientName,
              patientAge: record.patientAge,
              patientSex: record.patientSex,
              diagnoseCode: record.diagnoseCode,
              diagnoseName: record.diagnoseName,
              diagnoseRemark: record.diagnoseRemark,
              docCode: record.docCode,
              checkCode: record.checkCode,
              cureResult: record.cureResult,
              ensureFlag: record.ensureFlag,
              outpNo: record.outpNo
            }
          )
        }, 100)
        this.form.getFieldDecorator('inputDate', { initialValue: moment(record.inputDate, 'YYYY-MM-DD') })
        this.inputDateDateString = moment(record.inputDate).format('YYYY-MM-DD')
        this.form.getFieldDecorator('ensureDate', { initialValue: moment(record.ensureDate, 'YYYY-MM-DD') })
        this.ensureDateDateString = moment(record.ensureDate).format('YYYY-MM-DD')
        this.form.getFieldDecorator('checkDate', { initialValue: moment(record.checkDate, 'YYYY-MM-DD') })
        this.checkDateDateString = moment(record.checkDate).format('YYYY-MM-DD')
      },
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            values.inputDate = this.inputDateDateString
            values.ensureDate = this.ensureDateDateString
            values.checkDate = this.checkDateDateString
            OutpDiagnoseEdit(values).then((res) => {
              if (res.success) {
                this.$message.success('编辑成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('编辑失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      onChangeinputDate(date, dateString) {
        this.inputDateDateString = dateString
      },
      onChangeensureDate(date, dateString) {
        this.ensureDateDateString = dateString
      },
      onChangecheckDate(date, dateString) {
        this.checkDateDateString = dateString
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
